package com.qf.utils;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * zookeeper操作工具类
 * @author zhaojian
 */
public class ZkUtils {

    /**
     * 获取集群节点操作对象
     * @return
     */
    public static CuratorFramework getCf(){
        //1. 设置连接最大超时时间, 以及超时重试次数
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(3000,3);
        //2. 创建集群节点连接操作对象
        CuratorFramework cf = CuratorFrameworkFactory.builder()
                .connectString("192.168.200.129:2181,192.168.200.129:2182,192.168.200.129:2183")
                .retryPolicy(retryPolicy)//连接策略
                .build();
        //3. 开始连接
        cf.start();
        //4. 返回对象
        return cf;
    }
}